package com.ml.loan.common.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

/**
 * redission配置
 *
 * @param
 * @author Mickey
 * @date 2022/2/15 17:13
 * @return
 */
@Configuration
public class RedissonConfig {

    @Value("${spring.redis.redission.host:redis://localhost:6379}")
    private String redisAddress;

    @Value("${spring.redis.redission.password:123456}")
    private String redisPassword;

    @Bean(destroyMethod = "shutdown")
    public RedissonClient redisson() throws IOException {
        Config config = new Config();
        //监控锁的看门狗超时时间，默认300000（毫秒）
        config.setLockWatchdogTimeout(15000);
        config.useSingleServer()
                //#命令等待超时,单位：毫秒,默认3000；等待节点回复命令的时间。该时间从命令发送成功时开始计时
                .setTimeout(3000)
                //#命令失败重试次数，默认值:3
                .setRetryAttempts(3)
                //#ping节点超时,单位：毫秒,默认1000
                .setPingConnectionInterval(1000)
                .setAddress(redisAddress)
                .setPassword(redisPassword);
        RedissonClient redisson = Redisson.create(config);
        return redisson;
    }

}
